package com.sunricher.telinkblemeshlib.models;

import androidx.room.TypeConverter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.List;

public class RoomSceneActionConverters {
    private static final Gson gson = new Gson();

    @TypeConverter
    public static String fromActionList(List<RoomScene.Action> actions) {
        if (actions == null) {
            return null;
        }
        Type type = new TypeToken<List<RoomScene.Action>>() {}.getType();
        return gson.toJson(actions, type);
    }

    @TypeConverter
    public static List<RoomScene.Action> toActionList(String actionsString) {
        if (actionsString == null) {
            return null;
        }
        Type type = new TypeToken<List<RoomScene.Action>>() {}.getType();
        return gson.fromJson(actionsString, type);
    }
}
